package com.android.fragmentdemo.adapters
import android.content.Context
import com.android.fragmentdemo.CardItemActivity
import com.android.fragmentdemo.R
import com.hengfoxwolf.commonbase.base.databeans.SlipItem
import com.android.fragmentdemo.databinding.RvSlipItemLayoutBinding
import com.android.fragmentdemo.definervlayoutmanager.IItemTouchStatus
import com.android.fragmentdemo.startActivity
import java.util.Collections
import com.hengfoxwolf.commonbase.base.adapter.BaseRvAdapter

class SlideItemAdapter(private val context: Context) : BaseRvAdapter<SlipItem, RvSlipItemLayoutBinding>(), IItemTouchStatus {

    private var deleteCount = 0

    override fun getLayoutId(): Int = R.layout.rv_slip_item_layout

    override fun bindData(holder: ViewHolder, dataItem: SlipItem, position: Int) {
        holder.binding.itemSlipCvRoot.setCardBackgroundColor(context.resources.getColor(dataItem.color))
        val textNumber = "${position + 1 + deleteCount} / ${(itemDataSet?.size ?: 0) + deleteCount}"
        holder.binding.itemSlipTvNumber.text = textNumber
    }

    override fun onItemMove(fromPosition: Int, toPosition: Int): Boolean {
        itemDataSet?.let { Collections.swap(it, fromPosition, toPosition) }
        notifyItemMoved(fromPosition, toPosition)
        return true
    }

    override fun onItemRemove(position: Int): Boolean {
        itemDataSet?.removeAt(position)
        deleteCount++
        notifyDataSetChanged()
        return true
    }
}